<?php

namespace app\api\controller;

use app\BaseController;
use think\facade\Db;

class Owner extends BaseController
{
    //获取业主列表
    public function getFamilyList(){
        $room_user=$this->request->room_user;
        $list=Db::table("room_user")
            ->where("room_id",$room_user["room_id"])
            ->where("type","<>",1)
            ->select();
        $data["list"]=$list;
        $data["addStatus"]=true;
        parent::sendOutput($data);
    }
    public function addFamily(){
        $room_user=$this->request->room_user;
        $userid=$this->request->openid;
        $add["createAt"]=$userid;
        $add["room_id"]=$room_user["room_id"];
        $add["community_id"]=$room_user["community_id"];
        $add["community_name"]=$room_user["community_name"];
        $add["address"]=$room_user["address"];
        $add["type"]=2;
        $add["create_time"]=date('Y-m-d H:i:s');
        $add["name"]=request()->get("name");
        $add["mobile"]=request()->get("mobile");
        $roominfo=Db::table("roominfo")->where("owner_phone",$add["mobile"])->find();
        if(!empty($roominfo)){
            parent::sendOutput("该手机号为业主，不能添加为家人",500);
        }
        $res=Db::table("room_user")->insert($add);
        if($res){
            parent::sendOutput("添加成功");
        }else{
            parent::sendOutput("添加失败",500);
        }

    }
    public function getVisitorList(){
        $room_user=$this->request->room_user;
        $list=Db::table("visitor")
            ->where("room_id",$room_user["room_id"])
            ->select();
        $data["list"]=$list;
        $data["addStatus"]=true;
        parent::sendOutput($data);
    }
    public function addVisitor(){
        $room_user=$this->request->room_user;
        $userid=$this->request->openid;
        $add["createAt"]=$userid;
        $add["room_id"]=$room_user["room_id"];
        $add["community_id"]=$room_user["community_id"];
        $add["community_name"]=$room_user["community_name"];
        $add["address"]=$room_user["address"];
        $add["name"]=request()->get("name");
        $add["mobile"]=request()->get("mobile");
        $roominfo=Db::table("roominfo")->where("owner_phone",$add["mobile"])->find();
        if(!empty($roominfo)){
            parent::sendOutput("该手机号为业主，不能添加为家人",500);
        }
        $res=Db::table("visitor")->insert($add);
        if($res){
            parent::sendOutput("添加成功");
        }else{
            parent::sendOutput("添加失败",500);
        }

    }

}